package com.zmn.plat.admin.controller.service.item;

import com.zmn.common.constant.GlobalConsts;
import com.zmn.common.dto.VtDTO;
import com.zmn.common.dto2.ResponseDTO;
import com.zmn.common.utils.date.DateUtil;
import com.zmn.common.utils.logger.LoggerUtil;
import com.zmn.common.utils.number.NumberUtil;
import com.zmn.common.utils.office.ExcelUtil;
import com.zmn.common.utils.reflect.BeanMapper;
import com.zmn.common.utils.string.StringUtil;
import com.zmn.plat.business.interfaces.warranty.info.WarrantyInfoBService;
import com.zmn.plat.common.constant.CompanyConsts;
import com.zmn.plat.common.dictionary.BaseAcceptProjectTypeEnum;
import com.zmn.plat.common.enums.MaintainDifficultyEnum;
import com.zmn.plat.dubbo.utils.DubboConsts;
import com.zmn.plat.model.entity.base.acceptproject.AcceptProject;
import com.zmn.plat.model.entity.base.acceptproject.AcceptProjectQuery;
import com.zmn.plat.model.entity.base.fault.Fault;
import com.zmn.plat.model.entity.base.fault.FaultQuery;
import com.zmn.plat.model.entity.base.servicecontent.ServiceContent;
import com.zmn.plat.model.entity.base.servicecontent.ServiceContentQuery;
import com.zmn.plat.model.entity.category.BaseCategory;
import com.zmn.plat.model.entity.company.BaseCompany;
import com.zmn.plat.model.entity.company.BaseCompanyQuery;
import com.zmn.plat.model.entity.servcategory.ServCategory;
import com.zmn.plat.model.entity.service.group.ServiceGroup;
import com.zmn.plat.model.entity.service.group.ServiceGroupQuery;
import com.zmn.plat.model.entity.service.item.ServiceItem;
import com.zmn.plat.model.entity.service.item.ServiceItemCompanyQuery;
import com.zmn.plat.model.entity.service.item.servicetime.ServServiceTime;
import com.zmn.plat.model.entity.service.item.servicetime.ServServiceTimeQuery;
import com.zmn.plat.model.entity.service.itemdetail.ItemDetail;
import com.zmn.plat.model.entity.service.itempart.ItemPart;
import com.zmn.plat.model.entity.service.itempart.ItemPartQuery;
import com.zmn.plat.model.entity.service.tariff.ServiceTariff;
import com.zmn.plat.model.entity.warranty.content.WarrantyContent;
import com.zmn.plat.model.entity.warranty.content.WarrantyContentQuery;
import com.zmn.plat.model.entity.warranty.info.WarrantyInfo;
import com.zmn.plat.model.vo.SelectItemVO;
import com.zmn.plat.model.vo.company.BaseCompanyVO;
import com.zmn.plat.model.vo.service.item.ServiceItemDetailVO;
import com.zmn.plat.model.vo.service.item.ServiceItemWarrantyInfoVO;
import com.zmn.plat.model.vo.service.item.ServiceTimeVO;
import com.zmn.plat.model.vo.warranty.WarrantyInfoVO;
import com.zmn.plat.services.interfaces.base.acceptproject.AcceptProjectService;
import com.zmn.plat.services.interfaces.base.fault.FaultService;
import com.zmn.plat.services.interfaces.base.servicecontent.ServiceContentService;
import com.zmn.plat.services.interfaces.service.itemdetail.ItemDetailService;
import com.zmn.plat.services.interfaces.service.itempart.ItemPartService;
import com.zmn.scm2.common.model.dro.wms.goods.category.WmsGoodsCategoryDRO;
import com.zmn.scm2.common.model.query.wms.goods.category.GoodsCategoryShoppingQuery;
import com.zmn.scm2.dubbo.interfaces.wms.goods.category.GoodsCategoryListRemoteService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 故障分组项目表
 *
 * @author tanbiao
 * @since 2019-11-21 18:57:24
 */
@Slf4j
@RequestMapping("/service/item/")
@Controller
public class ServiceItemListController extends ServiceItemBaseController {

    @Resource
    WarrantyInfoBService warrantyInfoBService;

    @Resource
    ItemDetailService itemDetailService;
    @Resource
    FaultService faultService;
    @Resource
    AcceptProjectService acceptProjectService;
    @Resource
    ServiceContentService serviceContentService;
    @Resource
    ItemPartService itemPartService;
    @Reference(version = DubboConsts.INTERFACE_VERSION)
    GoodsCategoryListRemoteService goodsCategoryListRemoteService;

    /**
     * 详情
     *
     * @param itemId
     * @author tanbiao
     * @since 2019-11-21 18:57:24
     */
    @RequestMapping("detail")
    @RequiresPermissions("/service/item/detail.action")
    public ModelAndView detail(@RequestParam(value = "itemId", defaultValue = "0") Integer itemId,
                               @RequestParam(value = "groupId", defaultValue = "0") Integer groupId) {
        ServiceItemDetailVO detailVO = faultItemBService.getByItemIdAndGroupId(itemId, groupId);
        if (detailVO.getFaultTariff()!=null && detailVO.getFaultTariff().getTariffType() == 4){
            detailVO.getFaultItem().setHourFee(null);
            detailVO.getFaultItem().setTrafficFee(null);
            detailVO.getFaultItem().setCheckFee(null);
        }
        ModelAndView mav = new ModelAndView("service/item/detail");
        mav.addObject("faultItem", detailVO.getFaultItem());
        mav.addObject("faultGroup", detailVO.getGroup());
        // 单位
        mav.addObject("unit", listAllUnitName());
        mav.addObject("faultCategs", detailVO.getCategories());
        mav.addObject("hasDefaultItem", detailVO.isDefaultItem());
        mav.addObject("updateMyself", detailVO.isUpdateMyself());
        mav.addObject("servCategory", detailVO.getServCategory());
        mav.addObject("baseCategory", detailVO.getBaseCategory());
        mav.addObject("faultTariff", detailVO.getFaultTariff());
        mav.addObject("flag", 1);

        /**
         * 获取项目的验收项目、服务内容、故障
         */
        List<String> acceptProjectList = new ArrayList<>();
        StringBuilder acceptProjectBuilder = new StringBuilder();
        List<String> serviceContentList = new ArrayList<>();
        StringBuilder serviceContentBuilder = new StringBuilder();
        List<String> faultList = new ArrayList<>();
        StringBuilder faultListBuilder = new StringBuilder();
        Integer maintainDifficulty = null;
        if (itemId > 0){
            ItemDetail itemDetail = itemDetailService.findById(itemId);
            if (itemDetail!=null) {
//                acceptProjectList.forEach(item -> {
//                    if (!StringUtil.isBlank(itemDetail.getAcceptProjectList())) {
//                        List<String> items = Arrays.stream(itemDetail.getAcceptProjectList().split(",")).collect(Collectors.toList());
//                        if (items != null && items.size() > 0 && items.contains(item.getValue())) {
//                            item.setStatus(true);
//                        }
//                    }
//                });
//                serviceItemList.forEach(item -> {
//                    if (!StringUtil.isBlank(itemDetail.getServiceContentList())) {
//                        List<String> items = Arrays.stream(itemDetail.getServiceContentList().split(",")).collect(Collectors.toList());
//                        if (items != null && items.size() > 0 && items.contains(item.getValue())) {
//                            item.setStatus(true);
//                        }
//                    }
//                });
//                faultList.forEach(item -> {
//                    if (!StringUtil.isBlank(itemDetail.getFaultList())) {
//                        List<String> items = Arrays.stream(itemDetail.getFaultList().split(",")).collect(Collectors.toList());
//                        if (items != null && items.size() > 0 && items.contains(item.getValue())) {
//                            item.setStatus(true);
//                        }
//                    }
//                });

                if (!StringUtil.isBlank(itemDetail.getAcceptProjectList())) {
                    acceptProjectList = Arrays.stream(itemDetail.getAcceptProjectList().split(",")).collect(Collectors.toList());
                    List<Integer> queryIds = new ArrayList<>();
                    acceptProjectList.forEach(id->{
                        queryIds.add(Integer.valueOf(id));
                    });
                    List<AcceptProject> acceptProjects = acceptProjectService.listByIds(queryIds);
                    if (acceptProjects!=null && acceptProjects.size()>0){
                        // List<String> acceptProjectName = acceptProjects.stream().map(AcceptProject::getAcceName).collect(Collectors.toList());
                        List<String> acceptProjectName = new ArrayList<>();
                        acceptProjects.forEach(item->{
                            acceptProjectName.add(item.getAcceName()+"-"+item.getAcceId());
                        });
                        acceptProjectBuilder.append("已关联验收项目:"+String.join("、",acceptProjectName.toArray(new String[acceptProjectName.size()])));
                    }
                }

                if (!StringUtil.isBlank(itemDetail.getServiceContentList())) {
                    serviceContentList = Arrays.stream(itemDetail.getServiceContentList().split(",")).collect(Collectors.toList());
                    List<Integer> queryIds = new ArrayList<>();
                    serviceContentList.forEach(id->{
                        queryIds.add(Integer.valueOf(id));
                    });
                    List<ServiceContent> serviceContents = serviceContentService.listByIds(queryIds);
                    if (serviceContents!=null && serviceContents.size()>0){
                        // List<String> serviceContentName = serviceContents.stream().map(ServiceContent::getServDesc).collect(Collectors.toList());
                        List<String> serviceContentName = new ArrayList<>();
                        serviceContents.forEach(item->{
                            serviceContentName.add(item.getServDesc()+"-"+item.getServId());
                        });
                        serviceContentBuilder.append("已关联服务内容:"+String.join("、",serviceContentName.toArray(new String[serviceContentName.size()])));
                    }
                }
                if (!StringUtil.isBlank(itemDetail.getFaultList())) {
                    faultList = Arrays.stream(itemDetail.getFaultList().split(",")).collect(Collectors.toList());
                    List<Integer> queryIds = new ArrayList<>();
                    faultList.forEach(id->{
                        queryIds.add(Integer.valueOf(id));
                    });
                    List<Fault> faults = faultService.listByIds(queryIds);
                    if (faults!=null && faults.size()>0){
                        // List<String> faultName = faults.stream().map(Fault::getFaultName).collect(Collectors.toList());
                        List<String> faultName = new ArrayList<>();
                        faults.forEach(item->{
                            faultName.add(item.getFaultName()+"-"+item.getFaultId());
                        });
                        faultListBuilder.append("已关联故障:"+String.join("、",faultName.toArray(new String[faultName.size()])));
                    }
                }
                maintainDifficulty = itemDetail.getMaintainDifficulty();
            }
        }
        mav.addObject("acceptProjectList", acceptProjectList);
        mav.addObject("serviceContentList", serviceContentList);
        mav.addObject("faultList", faultList);
        mav.addObject("maintainDifficulty", maintainDifficulty);
        mav.addObject("acceptProjectNameList", acceptProjectBuilder.toString());
        mav.addObject("serviceContentNameList", serviceContentBuilder.toString());
        mav.addObject("faultNameList", faultListBuilder.toString());
        mav.addObject("maintainDifficultyList", MaintainDifficultyEnum.getMaintainDifficultyList());
        return mav;
    }

    /**
     * 设置保修信息
     *
     * @param servCategId
     * @param categOneId
     * @param groupId
     * @param itemId
     * @return
     */
    @RequestMapping("warrantyInfoList")
    @RequiresPermissions("/service/item/warrantyInfoList.action")
    public ModelAndView warrantyInfo(@RequestParam(value = "servCategId", defaultValue = "0") Integer servCategId,
                                     @RequestParam(value = "categOneId", defaultValue = "0") Integer categOneId,
                                     @RequestParam(value = "groupId", defaultValue = "0") Integer groupId,
                                     @RequestParam(value = "itemId", defaultValue = "0") Integer itemId) {
        ServiceItemWarrantyInfoVO detailVO =
                faultItemBService.getWarrantyInfoByServCategIdAndCategIdAndGroupIdAndItemId(servCategId, categOneId, groupId, itemId);

        ModelAndView mav = new ModelAndView("service/item/warrantyinfolist");
        mav.addObject("faultItem", detailVO.getFaultItem());
        mav.addObject("faultGroup", detailVO.getGroup());
        // 单位
        mav.addObject("categTwos", detailVO.getBaseCategories());
        Map<Integer, WarrantyInfoVO> map =
                detailVO.getWarrantyInfoVOS().stream().collect(Collectors.toMap(o -> o.getCategId(), o -> o, (o1, o2) -> o1));

        Map<Integer, List<WarrantyInfoVO>> dataMap =
                detailVO.getWarrantyInfoVOS().stream().collect(Collectors.groupingBy(WarrantyInfoVO::getCategId));
        Map<Integer, String> timeMap = new HashMap<>();
        dataMap.forEach((key, value) -> {
            ListSort(value);
            if (value != null && value.size() > 0) {
                timeMap.put(key, DateUtil.toString(value.get(0).getUpdateTime()) + "/" + value.get(0).getUpdater());
            }
        });

        mav.addObject("warrantyInfos", detailVO.getWarrantyInfoVOS());
        mav.addObject("map", map);
        mav.addObject("timeMap", timeMap);
        mav.addObject("servCategory", detailVO.getServCategory());
        mav.addObject("baseCategory", detailVO.getBaseCategory());
        mav.addObject("faultTariff", detailVO.getFaultTariff());
        mav.addObject("flag", 2);
        return mav;
    }

    @RequestMapping(value = "warrantyInfoDetail")
    @SuppressWarnings("Duplicates")
    @RequiresPermissions("/service/item/warrantyInfoDetail.action")
    public ModelAndView warrantyInfoDetail(@RequestParam(value = "bizType") Integer bizType,
                                           @RequestParam(value = "categId", defaultValue = "0") Integer categId,
                                           @RequestParam(value = "groupId", defaultValue = "0") Integer groupId,
                                           @RequestParam(value = "itemId", defaultValue = "0") Integer itemId) {
        ModelAndView mav = new ModelAndView("service/item/warrantyinfodetail");

        ServiceItem faultItem;
        ServiceGroup group = new ServiceGroup();
        if (itemId == 0) {
            faultItem = new ServiceItem();
        } else {
            faultItem = faultItemService.findByKey(itemId);
            groupId = faultItem.getGroupId();
        }
        if (groupId != 0) {
            group = faultGroupService.findByKey(groupId);
        }
        ServiceTariff faultTariff = faultTariffService.findByKey(group.getTariffId());
        BaseCategory baseCategory = baseCategoryService.findByKey(group.getCategOneId());
        List<BaseCategory> categTwos = baseCategoryService.listByParentId(baseCategory.getCategId(), GlobalConsts.YES);
        ServCategory servCategory = servCategoryService.findByKey(group.getServCategId());

        WarrantyInfo warrantyInfo = warrantyInfoService.findByItemIdAndCategIdAndBizType(itemId, categId, faultTariff.getBizType());
        if (warrantyInfo == null) {
            warrantyInfo = new WarrantyInfo();
        }

        WarrantyContentQuery warrantyContentQuery = new WarrantyContentQuery();
        warrantyContentQuery.setServCategId(group.getServCategId());
        warrantyContentQuery.setCategOneId(group.getCategOneId());
        warrantyContentQuery.setStatus(GlobalConsts.YES);
        warrantyContentQuery.setBizType(String.valueOf(faultTariff.getBizType()));
        List<WarrantyContent> warrantyContents = warrantyContentService.listByQuery(warrantyContentQuery);

        mav.addObject("faultItem", faultItem);
        mav.addObject("faultGroup", group);
        mav.addObject("servCategory", servCategory);
        mav.addObject("baseCategory", baseCategory);
        mav.addObject("faultTariff", faultTariff);
        mav.addObject("obj", warrantyInfo);
        mav.addObject("bizType", bizType);
        mav.addObject("categId", categId);
        mav.addObject("categTwos", categTwos);
        mav.addObject("itemId", itemId);
        mav.addObject("warrantyContents", warrantyContents);

        return mav;
    }

    @RequestMapping(value = "batchWarrantyInfoDetail")
    @SuppressWarnings("Duplicates")
    @RequiresPermissions("/service/item/batchWarrantyInfoDetail.action")
    public ModelAndView batchWarrantyInfoDetail(@RequestParam(value = "tariffId", defaultValue = "0") Integer tariffId,
                                                @RequestParam(value = "servCategId", defaultValue = "0") Integer servCategId,
                                                @RequestParam(value = "categOneId", defaultValue = "0") Integer categOneId,
                                                @RequestParam(value = "itemIds", defaultValue = "") String itemIds) {
        ModelAndView mav = new ModelAndView("service/item/batchwarrantyinfodetail");
        ServiceTariff faultTariff = faultTariffService.findByKey(tariffId);
        BaseCategory baseCategory = baseCategoryService.findByKey(categOneId);
        List<BaseCategory> categTwos = baseCategoryService.listByParentId(baseCategory.getCategId(), GlobalConsts.YES);
        ServCategory servCategory = servCategoryService.findByKey(servCategId);

        WarrantyInfo warrantyInfo = new WarrantyInfo();
        WarrantyContentQuery warrantyContentQuery = new WarrantyContentQuery();
        warrantyContentQuery.setServCategId(servCategId);
        warrantyContentQuery.setCategOneId(categOneId);
        warrantyContentQuery.setStatus(GlobalConsts.YES);
        warrantyContentQuery.setBizType(String.valueOf(faultTariff.getBizType()));
        List<WarrantyContent> warrantyContents = warrantyContentService.listByQuery(warrantyContentQuery);

        mav.addObject("servCategory", servCategory);
        mav.addObject("baseCategory", baseCategory);
        mav.addObject("faultTariff", faultTariff);
        mav.addObject("obj", warrantyInfo);
        mav.addObject("warrantyContents", warrantyContents);
        mav.addObject("itemIds", itemIds);
        mav.addObject("categTwos", categTwos);

        return mav;
    }

    /**
     * 描述: 根据条件导出保修信息Excel
     *
     * @param query 查询条件
     * @author tanghongjun
     * @since 11:43 2019/2/19
     **/
    @RequestMapping(value = "outputExcel")
    public void outputExcel(HttpServletResponse response, ServiceGroupQuery query) {
        query.setPageSize(getExportPageLimit(response));
        ArrayList<List> lists = warrantyInfoBService.outputProductExcel(query);
        try {
            String name = "保修信息.xlsx";
            name = new String(name.getBytes(), "ISO8859-1");
            ExcelUtil.export(response, lists, name, "sheet");
        } catch (Exception e) {
            LoggerUtil.error(this.getClass(), "导出报表出错" + e.getMessage(), e);
        }
    }

    /**
     * 描述: 根据项目id获取服务时长
     *
     * @param query 查询条件
     * @author yangshuangpiung
     * @since 2021-7-27
     **/
    @RequestMapping(value = "serviceTime")
    public ModelAndView serviceTime(ServiceItemCompanyQuery query) {
        ModelAndView mav = new ModelAndView("service/item/serviceTime");

        ServiceItem faultItem = faultItemService.findByKey(query.getItemId());
        ServiceItemDetailVO detailVO = faultItemBService.getByItemIdAndGroupId(query.getItemId(), faultItem.getGroupId());
        BaseCompanyQuery map = BeanMapper.map(query, BaseCompanyQuery.class);

        map.setType(CompanyConsts.COMPANY_TYPE_SUBSIDIARY);
        List<BaseCompanyVO> items = companyService.listVOByQuery(map);
        map.setTotalCount(items.size());
        List<ServiceTimeVO> serviceTimeVOS = translateShowCategName(items, query.getItemId(), query.getPageIndex(), query.getPageSize());
        mav.addObject("itemId", query.getItemId());
        mav.addObject("flag", 4);
        mav.addObject("faultItem", faultItem);
        mav.addObject("query", map);
        mav.addObject("faultGroup", detailVO.getGroup());
        mav.addObject("servCategory", detailVO.getServCategory());
        mav.addObject("baseCategory", detailVO.getBaseCategory());
        mav.addObject("faultTariff", detailVO.getFaultTariff());
        mav.addObject("items", serviceTimeVOS);
        return mav;
    }


    /**
     * 描述: 根据项目id获取服务时长
     *
     * @param query 查询条件
     * @author yangshuangpiung
     * @since 2021-7-27
     **/
    @RequestMapping(value = "partList")
    @RequiresPermissions("/service/item/partList.action")
    public ModelAndView partList(ItemPartQuery query) {
        ModelAndView mav = new ModelAndView("service/item/partList");

        ServiceItem item = faultItemService.findByKey(query.getItemId());
        ServiceItemDetailVO detailVO = faultItemBService.getByItemIdAndGroupId(query.getItemId(), item.getGroupId());
        /**
         * 获取所有已关联的配件
         */
        List<ItemPart> itemParts = itemPartService.listByQuery(query);
        GoodsCategoryShoppingQuery goodsCategoryShoppingQuery = new GoodsCategoryShoppingQuery();
        goodsCategoryShoppingQuery.setLevel(1);
        goodsCategoryShoppingQuery.setStatus(GlobalConsts.YES);
        List<VtDTO> wmsGoodsCategories = new ArrayList<>();
        ResponseDTO<List<WmsGoodsCategoryDRO>> result = goodsCategoryListRemoteService.listCategory(goodsCategoryShoppingQuery);
        if (result.isSuccess()){
            wmsGoodsCategories = result.getData().stream().map(categoryDRO ->
                    new VtDTO(categoryDRO.getCategId(), categoryDRO.getCategName())
            ).collect(Collectors.toList());
        }
        mav.addObject("itemParts", itemParts);
        mav.addObject("faultItem", item);
        mav.addObject("faultTariff", detailVO.getFaultTariff());
        mav.addObject("faultGroup", detailVO.getGroup());
        mav.addObject("wmsGoodsCategories", wmsGoodsCategories);
        mav.addObject("flag", 5);
        return mav;
    }

    /**
     * 填充服务时长,实现内存分页
     *
     * @param items      分公司列表
     * @param itemId     项目id
     * @param startIndex 开始页
     * @param pageSize   每页多少条
     * @return
     */
    private List<ServiceTimeVO> translateShowCategName(List<BaseCompanyVO> items, Integer itemId, Integer startIndex
            , Integer pageSize) {

        List<ServiceTimeVO> list = new ArrayList<>();
        List<Integer> companyIds = items.stream().map(BaseCompany::getCompanyId).distinct().collect(Collectors.toList());
        ServServiceTimeQuery query = new ServServiceTimeQuery();
        query.setCompanyIds(companyIds);
        query.setItemId(itemId);
        List<ServServiceTime> timeList = serviceTimeService.listByQuery(query);
        Map<Integer, Integer> serviceMinutes = timeList.stream().collect(Collectors.toMap(ServServiceTime::getCompanyId, ServServiceTime::getServiceMinutes));
        for (BaseCompanyVO item : items) {
            ServiceTimeVO time = BeanMapper.map(item, ServiceTimeVO.class);
            time.setServiceMinutes(NumberUtil.isNullOrZero(serviceMinutes.get(item.getCompanyId())) ? 0 : serviceMinutes.get(item.getCompanyId()));
            list.add(time);
        }

        startIndex = NumberUtil.isNullOrZero(startIndex) ? 0 : startIndex - 1;
        pageSize = NumberUtil.isNullOrZero(pageSize) ? 50 : pageSize;

        //内存分页
        list = list.stream().sorted(Comparator
                .comparing(ServiceTimeVO::getServiceMinutes)
                .thenComparing(ServiceTimeVO::getCompanyId)
                .reversed())
                .skip((startIndex * pageSize)).limit(pageSize)
                .collect(Collectors.toList());
        return list;
    }

    /**
     * 描述: 计算器3.0时，查询可用于关联的状态为开启的故障
     *
     * @param @param query
     * @return @return {@link ResponseDTO <List<>> }
     * @author chengguang
     * @since 2021/11/23 13:39
     */
    @RequestMapping("/listFault")
    @ResponseBody
    public ResponseDTO<Map<String, Object>> listFault(@ModelAttribute FaultQuery query) {
        try {
            Map<String, Object> result = new HashMap<>(4);
            query.setStatus(com.zmn.consts.GlobalConsts.YES);
            List<VtDTO> items = faultService.listPageByQuery(query).stream().map(item ->
                    new VtDTO(item.getFaultId(), item.getFaultName()+"-"+item.getFaultId())
            ).collect(Collectors.toList());
            result.put("list", items);
            result.put("totalCount", query.getTotalCount());
            return ResponseDTO.success(result);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("查询失败,Exception{},msg{}", e, e.getMessage());
            return ResponseDTO.fail("查询失败！");
        }
    }
    /**
     * 描述: 计算器3.0时，查询可用于关联的状态为开启的工程师验收项目
     *
     * @param @param query
     * @return @return {@link ResponseDTO <List<>> }
     * @author chengguang
     * @since 2021/11/23 13:39
     */
    @RequestMapping("/listAcceptProject")
    @ResponseBody
    public ResponseDTO<Map<String, Object>>listAcceptProject(AcceptProjectQuery query) {
        try {
            Map<String, Object> result = new HashMap<>(4);
            query.setStatus(com.zmn.consts.GlobalConsts.YES);
            query.setAcceType(BaseAcceptProjectTypeEnum.ENGINEER_ACCEPT.getCode());
            if(StringUtil.isNotBlank(query.getKeyWord())){
                query.setAcceIdOrName(query.getKeyWord());
            }
            List<VtDTO> items = acceptProjectService.listPageByQuery(query).stream().map(item ->
                    new VtDTO(item.getAcceId(), item.getAcceName()+"-"+item.getAcceId())
            ).collect(Collectors.toList());
            result.put("list", items);
            result.put("totalCount", query.getTotalCount());
            return ResponseDTO.success(result);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("查询失败,Exception{},msg{}", e, e.getMessage());
            return ResponseDTO.fail("查询失败！");
        }
    }
    /**
     * 描述: 计算器3.0时，查询可用于关联的状态为开启的验收项目
     *
     * @param @param query
     * @return @return {@link ResponseDTO <List<>> }
     * @author chengguang
     * @since 2021/11/23 13:39
     */
    @RequestMapping("/listServiceContent")
    @ResponseBody
    public ResponseDTO<Map<String, Object>>listServiceContent(ServiceContentQuery query) {
        try {
            Map<String, Object> result = new HashMap<>(4);
            query.setStatus(com.zmn.consts.GlobalConsts.YES);

            if(StringUtil.isNotBlank(query.getKeyWord())){
                query.setServIdOrDesc(query.getKeyWord());
            }

            List<VtDTO> items = serviceContentService.listPageByQuery(query).stream().map(item ->
                    new VtDTO(item.getServId(), item.getServDesc()+"-"+item.getServId())
            ).collect(Collectors.toList());
            result.put("list", items);
            result.put("totalCount", query.getTotalCount());
            return ResponseDTO.success(result);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("查询失败,Exception{},msg{}", e, e.getMessage());
            return ResponseDTO.fail("查询失败！");
        }
    }


    /**
     * 描述: 获取供应链商品分类
     *
     * @param @param query
     * @return @return {@link ResponseDTO <List<>> }
     * @author chengguang
     * @since 2021/11/23 13:39
     */
    @RequestMapping("/listCategory")
    @ResponseBody
    public ResponseDTO<List<WmsGoodsCategoryDRO>>listCategory(GoodsCategoryShoppingQuery query) {
        try {
            query.setStatus(GlobalConsts.YES);
            ResponseDTO<List<WmsGoodsCategoryDRO>> result = goodsCategoryListRemoteService.listCategory(query);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            log.error("查询失败,Exception{},msg{}", e, e.getMessage());
            return ResponseDTO.fail("查询失败！");
        }
    }



}
